//符咒、神魔录（神魔录重复、隐藏、一次性解锁）数据
let FuZhou = {};
let EnemyBook = {};
let ItemCatchLevel = {};
let ArmorEnemyId = {};
let SWDA_DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;


DataManager.isDatabaseLoaded = function(){
	if(!SWDA_DataManager_isDatabaseLoaded.call(this))
		return false;

	FuZhou.loadFuZhou();
	EnemyBook.loadEnemyBookDuplicate();
	EnemyBook.loadEnemyBookComplete();
	EnemyBook.loadEnemyBookHide();
	ItemCatchLevel.loadItemCatchLevel();
	ArmorEnemyId.loadArmorEnemyId();
	return true;
};

FuZhou.loadFuZhou = function(){
    for(let i = 1; i < $dataSkills.length; i++){
		let skill = $dataSkills[i];
		skill.isFu = false;
		skill.fuItemId = 0;

		if(skill.meta["Fu"])
            skill.isFu = true;
            skill.fuItemId = Number(skill.meta["Fu"]) || 0;
	}
};


EnemyBook.loadEnemyBookDuplicate = function(){
	for(var i = 1; i < $dataEnemies.length; i++){
		var enemy = $dataEnemies[i];
		enemy.duplicatedId = 0;

		if(enemy.meta["EnemyBook Duplicate"])
			enemy.duplicatedId = Number(enemy.meta["EnemyBook Duplicate"]) || 0;
	}
};

EnemyBook.loadEnemyBookComplete = function(){
	for(var i = 1; i < $dataEnemies.length; i++){
		var enemy = $dataEnemies[i];
		enemy.bookComplete = false; //是否遇到敌人一次即完全辨识
		if(enemy.meta["EnemyBook Complete"])
			enemy.bookComplete = true;
	}
};

EnemyBook.loadEnemyBookHide = function(){
	for(var i = 1; i < $dataEnemies.length; i++){
		var enemy = $dataEnemies[i];
		enemy.bookHide = false; //是否遇到敌人一次即完全辨识
		if(enemy.meta["EnemyBook Hide"])
			enemy.bookHide = true;
	}
};

// 物品等级（炼妖术合成系统用）
ItemCatchLevel.loadItemCatchLevel = function(){
	for(var i = 1; i < $dataItems.length; i++){
		var item = $dataItems[i];
		item.catchLevel = 0;
		if(item.meta["Catch Level"])
			item.catchLevel = Number(item.meta["Catch Level"]) || 0;
	}

	for(var i = 1; i < $dataWeapons.length; i++){
		var item = $dataWeapons[i];
		item.catchLevel = 0;
		if(item.meta["Catch Level"])
			item.catchLevel = Number(item.meta["Catch Level"]) || 0;
	}

	for(var i = 1; i < $dataArmors.length; i++){
		var item = $dataArmors[i];
		item.catchLevel = 0;
		if(item.meta["Catch Level"])
			item.catchLevel = Number(item.meta["Catch Level"]) || 0;
	}
};

// 物品等级（炼妖术合成系统用）
ArmorEnemyId.loadArmorEnemyId = function(){
	for(var i = 1; i < $dataArmors.length; i++){
		var item = $dataArmors[i];
		item.enemyId = 0;
		if(item.meta["Enemy Id"])
			item.enemyId = Number(item.meta["Enemy Id"]) || null;
	}
};

//判断是否是普攻技能（包含非1号技能）[涉及game_action，以及各种神魔信息界面]
DataManager.isAttack = function (skill, defaultAttackSkillId) {
	// 包含各种特殊功能的普攻
	defaultAttackSkillId = defaultAttackSkillId || 1;
	const extraAttackSkillId = this.extraAttackSkillId();
	let result = skill === $dataSkills[defaultAttackSkillId];
	for (let i = 0; i < extraAttackSkillId.length; i++) {
	  result = result || skill === $dataSkills[extraAttackSkillId[i]];
	}
	return result;
  };

// 各种特殊功能的普攻技能编号
DataManager.extraAttackSkillId = function () {
	return [70, 184, 186, 187, 190, 191, 198];
};


// 物品图标编号顺序映射
DataManager.itemSortMapping = function (index) {
	// 调整顺序
	switch (index) {
		//case 表示原编号（不按顺序），return新编号（按顺序）
		case 179:
			return 176;
		case 180:
			return 177;
		case 176:
			return 178;
		case 177:
			return 179;
		case 178:
			return 180;
		default:
			return index;
	}
};